package com.ruoyi.Echarts.service.IService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.DegreeCommit.domain.DegreeCommit;
import com.ruoyi.DegreeCommit.mapper.DegreeCommitMapper;
import com.ruoyi.Echarts.service.IEchartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

@Service
public class EchartsServiceImpl implements IEchartsService {


    @Autowired
    private DegreeCommitMapper degreeCommitMapper;

    @Override
    public List<Map<String, Object>> getData() {
        List<Map<String, Object>> nodes = new ArrayList<>();

        String[] names = {"学生信息","导师信息","课程信息","获奖信息","论文信息","科研项目"};

        QueryWrapper<DegreeCommit> queryWrapper = new QueryWrapper();
        queryWrapper.eq("u_id",getLoginUser().getUserId());
        DegreeCommit degreeCommit = degreeCommitMapper.selectOne(queryWrapper);
        if (degreeCommit == null) {
            return null;
        }


        // 手动映射names与degreeCommit的属性值
        Map<String, Object> nameToValueMap = new HashMap<>();
        nameToValueMap.put("学生信息", degreeCommit.getStudentInformation());
        nameToValueMap.put("导师信息", degreeCommit.getMentorInformation());
        nameToValueMap.put("课程信息", degreeCommit.getCourceInformation());
        nameToValueMap.put("获奖信息", degreeCommit.getAwardInformation());
        nameToValueMap.put("论文信息", degreeCommit.getPaperInformation());
        nameToValueMap.put("科研项目", degreeCommit.getResearchProject());

        for (String name : names) {
            Map<String, Object> node = new HashMap<>();
            node.put("name", name);
            node.put("value", nameToValueMap.get(name));
            nodes.add(node);
        }
        return nodes;
    }
}
